<?php 

include('db.inc.php');
/*
*初始$cid是数据表的id
*第一次循环得到一条数据的pid,然后将其以id的形式再循环
*krsort();对数组按照键名逆向排序
*
*/



function getCatePath($cid,&$result=array()){
	$sql = "select * from deepcate where id = $cid";
	$re = mysql_query($sql);
	$row = mysql_fetch_assoc($re);
	if($row){
		$result[] = $row;

		getCatePath($row['pid'],$result);
	}
	krsort($result);
	return $result;
}

function displayCatePath($cid,$url="cate.php?cid="){
	$res = getCatePath($cid);
	$str = '';
	foreach($res as $k=>$val){
		//href='cate.php?cid={$val['id']}
		$str .= "<a href='{$url}{$val['id']}'>{$val['catename']}</a> >";
	}
	return $str;
}

echo displayCatePath(12,'cate.php?page=1&id=');
 ?>